﻿using DevExpress.XtraTab;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoMan.Helper
{
    public class TabPageHelper
    {
        private XtraTabControl container;
        public TabPageHelper(XtraTabControl tabControl)
        {
            container = tabControl;
        }
        /// <summary>
        /// 切换页面
        /// </summary>
        /// <param name="ctrl"></param>
        public void LoadPage(Control ctrl, string text)
        {
            //判断是否已创建过
            foreach (XtraTabPage page in container.TabPages)
            {
                if (page.Text == text)
                {
                    container.SelectedTabPage = page;//显示该页
                    return;
                }
            }

            //增加tabpage
            XtraTabPage xpage = new XtraTabPage();
            xpage.Name = ctrl.Name;
            xpage.Text = text;
            ctrl.Dock = DockStyle.Fill;
            xpage.Controls.Add(ctrl);//添加要增加的控件
            container.TabPages.Add(xpage);
            container.SelectedTabPage = xpage;//显示该页
        }
    }
}
